/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var clicked = new Object();
var clicked2 = new Object();
var clicked3 = new Object();
var wordNum = 1;
var num = 1;
var friend = new Array();
var friendName = new Array();

function friendList(){
        for(i=0;i<friend.length;i++){
            var query = FB.Data.query('select name, uid from user where uid = '+friend[i]);
            query.wait(function(rows) {
                friendName[i] = rows[0].name;
                if(friendName[i].length > 16)
                    friendName[i] = friendName[i].substr(0, 12) + "...";
                $("#highscores").append("<td class='tdPic'><img src='https://graph.facebook.com/"+rows[0].uid+"/picture' class='pic' alt='pic' /><br /><label class='name'>"+friendName[i]+"</label><br />1000</td>");
			
            });	
			
        }
	
		 
}
		
			
function anEvent(row, newClass)
{
    if(row.className != "selected2") {
        row.className = newClass;
        if(newClass == "selected2") {
            //if(category == "place")
            document.getElementById("td1").innerHTML = row.innerHTML;
			
            //else if(category == "animal")
            document.getElementById("td2").innerHTML = row.innerHTML;
			
            //else if(category == "name")
            document.getElementById("td3").innerHTML = row.innerHTML;
			
            //else if(category == "thing")
            document.getElementById("td4").innerHTML = row.innerHTML;
			
            document.getElementById("td5").innerHTML = 200000;
			
            clicked.className = "";
            clicked = row;
        }
    }
}
//dynamic row addition

function insRow()
{
    var str="Eugene";
    for (j=1;j<=10;j++)
    {
        var tr=document.getElementById('games').insertRow(j);
        for (i=1;i<=4;i++)
        {
            var td = document.createElement('td');
            td.innerHTML =str+num;
            td.setAttribute('onmouseover', "anEvent(this, 'highlight2');");
            td.setAttribute('onmouseout',"anEvent(this, '');");
            td.setAttribute('onclick', "anEvent(this, 'selected2');");
            tr.appendChild(td);
            num++;
        }
    }
}
			
//click highlight
function pressed(button)
{
    var val = button.getAttribute("value");
    if(val == "Join Game")
        window.location="game.html";
    else if(val == "Create Game")
        window.location="create.html";
}

function anEvent2(row,newClass)
{
    var rowHtml = "div";
    var count = 1;
    var loop = true;
    while (loop)
    {
        if(rowHtml+count+1 ==row.id||rowHtml+count+2 ==row.id||rowHtml+count+3 ==row.id){
            if(row.className != "selected") {
                document.getElementById(rowHtml+count+1).className = newClass;
                document.getElementById(rowHtml+count+2).className = newClass;
                document.getElementById(rowHtml+count+3).className = newClass;
                if(newClass == "selected") {
                    clicked.className = "table";
                    clicked2.className = "table";
                    clicked3.className = "table";
                    clicked = document.getElementById(rowHtml+count+1);
                    clicked2 = document.getElementById(rowHtml+count+2);
                    clicked3 = document.getElementById(rowHtml+count+3);
                }
            }
            loop=false;
        }
        count++;
    }
			   
}
			
//dynamic row addition
                
function createDiv(){
    for(j=1;j<=30;j++){
        for(i=1;i<=3;i++){
            if(i==1)
                str = "game" + wordNum;
            else if(i==2){
				
                if(j%3==0)
                    str = "Eugene";
				
                else if(j%3==1)
                    str ="Anthony";
				
                else
                    str = "Mark"
            }
            else{
				
                if(j%2==0)
                    str = "Waiting";
				
                else
                    str ="Playing";
				
            }
		
            var newDiv = document.createElement("div");
			
            newDiv.id="div"+j+i;
            newDiv.className="table";
            newDiv.setAttribute('onmouseover', "anEvent2(this, 'highlight');");
            newDiv.setAttribute('onmouseout',"anEvent2(this, 'table');");
            newDiv.setAttribute('onclick', "anEvent2(this, 'selected');");
			
                        
            newDiv.innerHTML = str;
			
            document.getElementById("row"+i).appendChild(newDiv);
						
        }
        wordNum++;
    }
}

